<!--
 * @FilePath     : /study_code/layui/19-2-10.html
 * @Description  :
 * @Date         : 2025-04-15 09:09:50
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-15 09:09:59
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
    <!-- css 是 treetable.js 中 js 代码追加 -->
  </head>
  <body>
    <table id="table1" class="layui-table" lay-filter="table1"></table>

    <!-- 2、操作列 -->
    <script type="text/html" id="oper-col">
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script src="/layui/dist/layui.js"></script>
    <script src="/layui/treetable-lay/common.js"></script>
    <script>
      layui
        .config({
          base: '/layui/extends_modules',
        })
        .extend({
          treetable: '/treetable-lay/treetable',
        })
        .use(['form', 'treetable', 'layer'], function () {
          var layer = layui.layer,
            form = layui.form,
            $ = layui.jquery,
            table = layui.table
            treetable = layui.treetable

          // 默认配置项见 https://gitcode.com/fangyinggui/study_code/blob/main/layui/treetable-lay/common.js
          treetable.render({
            ...defaultConfig,
            ...{
              cols: [
                [
                  { type: 'numbers' },
                  { field: 'name', title: 'name' },
                  { field: 'id', title: 'id' },
                  { field: 'sex', title: 'sex' },
                  { field: 'pid', title: 'pid' },
                  // 1、cols 子项，某列，templet 配置工具栏；
                  { templet: '#oper-col', title: 'oper' },
                ],
              ],
            },
          })

          // 3、监听工具条 （依赖 table 模块）
          table.on('tool(table1)', function (obj) {
            var data = obj.data
            var layEvent = obj.event

            if (layEvent === 'del') {
              layer.msg('删除' + data.id)
            } else if (layEvent === 'edit') {
              layer.msg('修改' + data.id)
            }
          })
        })
    </script>
  </body>
</html>
